package com.example.two.service.impl;

import com.example.two.domain.User;
import com.example.two.mapper.UserMapper;
import com.example.two.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserById(Long id){
        return userMapper.getUserById(id);
    };

    @Override
    public List<User> getAll(){
        return userMapper.getAllUser();
    };

    @Override
    public boolean insert(User user){
        return userMapper.insertUser(user)>0;
    };

    @Override
    public boolean update(User user){
        return userMapper.updateUser(user)>0;
    };

    @Override
    public boolean delete(Long id){
        return userMapper.deleteUser(id)>0;
    };

    @Override
    public User  getUserWithOrders(Long id){
        return userMapper.getUserWithOrders(id);
    };

    @Override
    public List<Map<String, Object>> getUserOrderCount() {
        return userMapper.getUserOrderCount();
    }

    @Override
    public List<User> getUsersWithOrders() {
        return userMapper.getUsersWithOrders();
    }

    @Override
    public List<Map<String, Object>> countUsersByAgeGroup() {
        return userMapper.countUsersByAgeGroup();
    }
}
